#include <graphics/lge_graphicssubsystem.h>

bool GraphicsSubsystem::init(const Configuration & config)
{
	mConfiguration = config;
	mJobSubsystem = &JobSubsystem::instance();

	if (!initWindow())
		return false;

	if (!initGL())
		return false;

	Job renderingJob = createJob(&GraphicsSubsystem::update, this);
	mJobSubsystem->pushJob(renderingJob, JobSubsystem::MainThread);

	return true;
}

bool GraphicsSubsystem::update()
{
	static float f = 0.0f;

	while (PeekMessage(&mMsg,NULL,0,0,PM_REMOVE)!=0)
	{
		TranslateMessage(&mMsg);
		DispatchMessage(&mMsg);
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	glRotatef(f, 0, 0, 1.0f);

	f+= 0.1f;

	// Draw
	glBegin(GL_LINES);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex2f(0.0f, 100.0f);
	glEnd();

	SwapBuffers(mHdc);

	Job renderingJob = createJob(&GraphicsSubsystem::update, this);
	mJobSubsystem->pushJob(renderingJob, JobSubsystem::MainThread);
	
	return true;
}
